﻿using System;
using System.Collections.ObjectModel;
using System.Linq;

namespace Com.Lancetinc.Evs.Helpers
{
    public static class ComboBoxSelectItemsHelper
    {
        public static string NormalizeItemsText(string itemsText)
        {
            var lines = ToItemsArray(itemsText);
            return String.Join("\n", lines);
        }

        public static string[] ToItemsArray(string itemsText)
        {
            if (String.IsNullOrEmpty(itemsText))
            {
                return new string[] { };
            }
            var lines = itemsText.Split('\r', '\n');
            lines = lines.AsQueryable().Select(x => x.Trim()).Distinct().Where(x => x.Length > 0).ToArray();
            return lines;
        }

        public static void InitializeItems(ObservableCollection<string> items, string itemsText)
        {
            var lines = ToItemsArray(itemsText);
            items.Clear();
            foreach (var line in lines)
            {
                items.Add(line);
            }
        }

    }
}
